#include "StdAfx.h"
#include "AsciiFont.h"

//=============================================================================
CAsciiFont::CAsciiFont()
{
	mFontList = 0;
	mColor[0] = mColor[1] = mColor[2] = 1.0f;
}

//=============================================================================
CAsciiFont::~CAsciiFont()
{
	Destroy();
}

//=============================================================================
void CAsciiFont::SetTextColour( float r, float g, float b )
{
	mColor[0] = r;
	mColor[1] = r;
	mColor[2] = r;
}

//=============================================================================
bool CAsciiFont::Create( const char *pFaceName, int height, int weight,
	bool italic, bool underline, bool strikeOut )
{
	HDC   hDC = wglGetCurrentDC();
	int   nCharSet = ANSI_CHARSET;
	HFONT hFont = NULL;

	if ( _stricmp( pFaceName, "symbol" ) == 0 )
		nCharSet = SYMBOL_CHARSET;

	hFont = CreateFontA( height, 0, 0, 0, weight, italic, underline, strikeOut,
		nCharSet, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
		DRAFT_QUALITY, DEFAULT_PITCH,
		pFaceName );

	SelectObject( hDC, hFont );

	mFontList = glGenLists( 256 );
	wglUseFontBitmaps( hDC, 0, 255, mFontList );

	return mFontList != 0;
}

//=============================================================================
void CAsciiFont::Destroy()
{
	if ( glIsList( mFontList ) )
	{
		glDeleteLists( mFontList, 256 );
	}
}


//=============================================================================
void CAsciiFont::DrawText( float x, float y, const char *str )
{
	glPushAttrib( GL_CURRENT_BIT | GL_ENABLE_BIT );
	glDisable( GL_TEXTURE_2D );
	glDisable( GL_LIGHTING );
	glDisable( GL_FOG );

	glColor3fv( mColor );
	glRasterPos2f( x, y );

	glListBase( mFontList );
	glCallLists( strlen( str ), GL_UNSIGNED_BYTE, str );

	glRasterPos2f( 0.0f, 0.0f );
	glPopAttrib();
}